<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>仓租收支明细管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">
		var validateForm;
		var $table; // 父页面table表格id
		var $topIndex;//弹出窗口的 index
		function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $table = table;
			  $topIndex = index;
			  jp.loading();
			  $("#inputForm").submit();
			  return true;
		  }

		  return false;
		}

		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					jp.post("${ctx}/infor/storeBudget/save",$('#inputForm').serialize(),function(data){
						if(data.success){
	                    	$table.bootstrapTable('refresh');
	                    	jp.success(data.msg);
	                    	jp.close($topIndex);//关闭dialog

	                    }else{
            	  			jp.error(data.msg);
	                    }
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
	        $('#rq').datetimepicker({
				 format: "YYYY-MM"
		    });
		});
		
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="storeBudget" action="${ctx}/infor/storeBudget/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
			<form:hidden path="jszt"/>
			<form:hidden path="djzt"/>
			<form:hidden path="kpzt"/>
		<sys:message content="${message}"/>
		<table class="table table-bordered">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right">项目：</label></td>
					<td class="width-35">
						<form:input path="pro" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">单据号：</label></td>
					<td class="width-35">
						<form:input path="djh" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">日期：</label></td>
					<td class="width-35">
						<p class="input-group">
							<div class='input-group form_datetime' id='rq'>
			                    <input type='text'  name="rq" class="form-control "  value="<fmt:formatDate value="${storeBudget.rq}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
			                    <span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
			                </div>
			            </p>
					</td>
					<td class="width-15 active"><label class="pull-right">税率：</label></td>
					<td class="width-35">
						<form:input path="sl" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
		   </table>
			<ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-01" aria-expanded="true">仓租收入</a>
				</li>
				<li class=""><a data-toggle="tab" href="#tab-02" aria-expanded="true">仓租支出</a>
				</li>
			</ul>
		<div class="tab-content">
		<div id="tab-01" class="tab-pane fade in  active">
			<table class="table table-bordered">
				<tr>
					<td class="width-15 active"><label class="pull-right">仓库面积：</label></td>
					<td class="width-35">
						<form:input path="mj" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">收入单价：</label></td>
					<td class="width-35">
						<form:input path="srdj" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">收入附加：</label></td>
					<td class="width-35">
						<form:input path="srfj" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">不含税收入：</label></td>
					<td class="width-35">
						<form:input path="sr" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">含税收入：</label></td>
					<td class="width-35">
						<form:input path="hssr" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">仓库管理收入：</label></td>
					<td class="width-35">
						<form:input path="glsr" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">总收入：</label></td>
					<td class="width-35">
						<form:input path="zsr" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">说明：</label></td>
					<td class="width-35">
						<form:input path="sm" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
			</table>
			<div class="tabs-container">
				<ul class="nav nav-tabs">
					<li class="active"><a data-toggle="tab" href="#tab-2" aria-expanded="false">仓租管理收入：</a>
					</li>
				</ul>
				<div class="tab-content">
					<div id="tab-2" class="tab-pane fade in  active">
						<a class="btn btn-white btn-sm" onclick="addRow('#budgetIncomeList', budgetIncomeRowIdx, budgetIncomeTpl);budgetIncomeRowIdx = budgetIncomeRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
						<table class="table table-striped table-bordered table-condensed">
							<thead>
							<tr>
								<th class="hide"></th>
								<th>收入类型</th>
								<th>收入金额</th>
								<th>收入说明</th>
								<th width="10">&nbsp;</th>
							</tr>
							</thead>
							<tbody id="budgetIncomeList">
							</tbody>
						</table>
						<script type="text/template" id="budgetIncomeTpl">//<!--
				<tr id="budgetIncomeList{{idx}}">
					<td class="hide">
						<input id="budgetIncomeList{{idx}}_id" name="budgetIncomeList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="budgetIncomeList{{idx}}_delFlag" name="budgetIncomeList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>

					<td>
					<select name="budgetIncomeList[{{idx}}].type" id="budgetIncomeList{{idx}}_type" class="form-control ">
					<c:forEach items="${fns:getDictList('czsr')}" var="i">
							<option value="${i.value}" >${i.value}</option>
						</c:forEach>
					</select>
					</td>


					<td>
						<input id="budgetIncomeList{{idx}}_je" name="budgetIncomeList[{{idx}}].je" type="text" value="{{row.je}}"    class="form-control "/>
					</td>


					<td>
						<input id="budgetIncomeList{{idx}}_remarks" name="budgetIncomeList[{{idx}}].remarks" value="{{row.remarks}}"   class="form-control ">
					</td>

					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#budgetIncomeList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
						</script>
						<script type="text/javascript">
                            var budgetIncomeRowIdx = 0, budgetIncomeTpl = $("#budgetIncomeTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                            $(document).ready(function() {
                                var data = ${fns:toJson(storeBudget.budgetIncomeList)};
                                for (var i=0; i<data.length; i++){
                                    addRow('#budgetIncomeList', budgetIncomeRowIdx, budgetIncomeTpl, data[i]);
                                    budgetIncomeRowIdx = budgetIncomeRowIdx + 1;
                                }
                            });
						</script>
					</div>
				</div>
			</div>
		</div>
		<div id="tab-02" class="tab-pane fade">
			<table class="table table-bordered">
				<tr>
					<td class="width-15 active"><label class="pull-right">仓库面积(支出)：</label></td>
					<td class="width-35">
						<form:input path="zcmj" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">支出单价：</label></td>
					<td class="width-35">
						<form:input path="zcdj" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">支出附加：</label></td>
					<td class="width-35">
						<form:input path="zcfj" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">不含税支出：</label></td>
					<td class="width-35">
						<form:input path="zc" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">含税支出：</label></td>
					<td class="width-35">
						<form:input path="hszc" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">仓库管理支出：</label></td>
					<td class="width-35">
						<form:input path="glzc" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">总支出：</label></td>
					<td class="width-35">
						<form:input path="zzc" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">说明(支出)：</label></td>
					<td class="width-35">
						<form:input path="zcsm" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<%--<tr>--%>
					<%--<td class="width-15 active"><label class="pull-right">罚款：</label></td>--%>
					<%--<td class="width-35">--%>
						<%--<form:input path="fk" htmlEscape="false"    class="form-control "/>--%>
					<%--</td>--%>
					<%--<td class="width-15 active"><label class="pull-right">单据状态：</label></td>--%>
					<%--<td class="width-35">--%>
						<%--<form:input path="djzt" htmlEscape="false"    class="form-control "/>--%>
					<%--</td>--%>
				<%--</tr>--%>
				<%--<tr>--%>
					<%--<td class="width-15 active"><label class="pull-right">开票状态：</label></td>--%>
					<%--<td class="width-35">--%>
						<%--<form:input path="kpzt" htmlEscape="false"    class="form-control "/>--%>
					<%--</td>--%>
					<%--<td class="width-15 active"><label class="pull-right">结算状态：</label></td>--%>
					<%--<td class="width-35">--%>
						<%--<form:input path="jszt" htmlEscape="false"    class="form-control "/>--%>
					<%--</td>--%>
				<%--</tr>--%>
		 	</tbody>
		</table>
		<div class="tabs-container">
            <ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">仓租管理支出：</a>
                </li>

            </ul>
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#budgetExpenList', budgetExpenRowIdx, budgetExpenTpl);budgetExpenRowIdx = budgetExpenRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th>支出类型</th>
						<th>支出金额</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="budgetExpenList">
				</tbody>
			</table>
			<script type="text/template" id="budgetExpenTpl">//<!--
				<tr id="budgetExpenList{{idx}}">
					<td class="hide">
						<input id="budgetExpenList{{idx}}_id" name="budgetExpenList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="budgetExpenList{{idx}}_delFlag" name="budgetExpenList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
					<select name="budgetExpenList[{{idx}}].type" id="budgetExpenList{{idx}}_type" class="form-control ">
					<c:forEach items="${fns:getDictList('czzc')}" var="i">
							<option value="${i.value}" >${i.value}</option>
						</c:forEach>
					</select>
					</td>
					
					
					<td>
						<input id="budgetExpenList{{idx}}_je" name="budgetExpenList[{{idx}}].je" type="text" value="{{row.je}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="budgetExpenList{{idx}}_remarks" name="budgetExpenList[{{idx}}].remarks" value="{{row.remarks}}"    class="form-control ">
					</td>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#budgetExpenList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var budgetExpenRowIdx = 0, budgetExpenTpl = $("#budgetExpenTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(storeBudget.budgetExpenList)};
					for (var i=0; i<data.length; i++){
						addRow('#budgetExpenList', budgetExpenRowIdx, budgetExpenTpl, data[i]);
						budgetExpenRowIdx = budgetExpenRowIdx + 1;
					}
				});
			</script>
			</div>

		</div>
		</div>
		</div>
		</div>
		</form:form>
</body>
</html>